package two;

import java.lang.management.ManagementFactory;

import javax.management.MBeanServer;
import javax.management.ObjectName;

import one.Hello;

import com.sun.jdmk.comm.HtmlAdaptorServer;

/**
 * 代理层  HelloAgent类
 *
 */
public class HelloAgent {

	public static void main(String[] args) throws Exception {
		//MBeanServer server = MBeanServerFactory.createMBeanServer();
		//创建一个MBeanServer，用来做MBean的容器
		MBeanServer server = ManagementFactory.getPlatformMBeanServer();
		//创建一个ObjectName,liuys:name=helloWorld是有命名规则的，为“域名：name=MBean名称”，域名和MBean名称可以随便写
		ObjectName helloName = new ObjectName("liuys:name=helloWorld");
		Hello hello = new Hello();
		//将hello注入到MBeanServer
		server.registerMBean(hello, helloName);
		
		ObjectName adapterName = new ObjectName("HelloAgent:name=htmladapter,port=8082");
		//创建一个AdapterServer，这个对象决定了MBean的管理界面，这里使用最普通的html界面。AdaptorServer其实也是一个MBean
		HtmlAdaptorServer adaptor = new HtmlAdaptorServer();
		server.registerMBean(adaptor, adapterName);
		
		Jack jack = new Jack();
		server.registerMBean(jack, new ObjectName("HelloAgent:name=jack"));
										//listener       filter  handback
		jack.addNotificationListener(new HelloListener(), null, hello);
		//启动adaptor代理服务
		adaptor.start();
		System.out.println("start.....................");
	}
}
